﻿using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
using GrayParrot.Web.Controls;
using System.Linq;
using System.Linq.Expressions;
using GrayParrot.Core.Filters;

namespace $rootnamespace$
{
    #region Comments...
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>
    /// using for datatables.net general filter...
    ///
    ///   MyGeneralFilterBag m_generalFilter = new MyGeneralFilterBag();
    ///   m_generalFilter.SearchPattern = searchPattern;     <-- general filter uses a standard seach pattern -->
    ///   return m_generalFilter.SetUpFilter();
    ///   
    /// The implementation of the SetupFilter method is...  
    /// public override Expression<Func<sogei_CalendarioAvvenimentiBag, bool>> SetUpFilter()
    /// {
    ///     var predicate = PredicateBuilder.False<sogei_CalendarioAvvenimentiBag>();
    ///
    ///     if (!string.IsNullOrWhiteSpace(SearchPattern))
    ///     {
    ///         predicate = predicate.Or(im => im.Campo1 != null && im.Campo1.ToString().Contains(SearchPattern));
    ///         predicate = predicate.Or(im => im.Campo2 != null && im.Campo2.ToString().Contains(SearchPattern));
    ///         predicate = predicate.Or(im => im.Campo3 != null && im.Campo3.ToLower().Contains(SearchPattern.ToLower()));
    ///     }
    ///
    ///     return predicate;
    /// }
    /// 
    /// ------------------------------------------------------------------------------------- 
    /// 
    /// using for datatables.net specific column filter...
    /// 
    ///   MyColumnsFilterBag m_filterBag = new MyColumnsFilterBag();
    ///  
    ///   string m_dummy = m_filterBag.GetValueOrDefault<string>(columnSearch[ColumnIndex]);
    ///
    ///   m_filterBag.IdAvvenimento = m_filterBag.GetValueOrDefault<int>(columnSearch[ColumnIndex]);
    ///   m_filterBag.Descrizione = columnSearch[ColumnIndex];
    ///   m_filterBag.Data = m_filterBag.ManageDates(columnSearch[ColumnIndex]);
    ///
    ///   return m_filterBag.SetUpFilter();
    /// 
    /// The implementation of the SetupFilter method is...
    /// public override Expression<Func<sogei_CalendarioAvvenimentiBag, bool>> SetUpFilter()
    /// {
    ///    var predicate = PredicateBuilder.True<sogei_CalendarioAvvenimentiBag>();
    ///    // Date Fileter example
    ///    if (this.UseDates)
    ///    {
    ///        // aggiungi al filtro il controllo sulla data...
    ///        if ((this.PeriodFrom != null) && (this.PeriodTo != null))
    ///        {
    ///            predicate = predicate.And(im => (System.Data.Entity.DbFunctions.TruncateTime(im.Data) >= System.Data.Entity.DbFunctions.TruncateTime(this.PeriodFrom)) &&
    ///                                             System.Data.Entity.DbFunctions.TruncateTime(im.Data) <= System.Data.Entity.DbFunctions.TruncateTime(this.PeriodTo));
    ///        }
    ///
    ///        if ((this.PeriodFrom != null) && (this.PeriodTo == null))
    ///        {
    ///            predicate = predicate.And(im => System.Data.Entity.DbFunctions.TruncateTime(im.Data) >= System.Data.Entity.DbFunctions.TruncateTime(this.PeriodFrom));
    ///        }
    ///
    ///        if ((this.PeriodFrom == null) && (this.PeriodTo != null))
    ///        {
    ///            predicate = predicate.And(im => System.Data.Entity.DbFunctions.TruncateTime(im.Data) <= System.Data.Entity.DbFunctions.TruncateTime(this.PeriodTo));
    ///        }
    ///    }
    ///    else
    ///    {
    ///        if (Data != default(DateTime))
    ///        {
    ///            predicate = predicate.And(im => System.Data.Entity.DbFunctions.TruncateTime(im.Data) == System.Data.Entity.DbFunctions.TruncateTime(Data));
    ///        }
    ///    }
    ///
    ///    if (IdAvvenimento != default(int))
    ///    {
    ///        predicate = predicate.And(im => im.IdAvvenimento == IdAvvenimento);
    ///    }
    ///
    ///    if (!string.IsNullOrWhiteSpace(Descrizione))
    ///    {
    ///        predicate = predicate.And(im => im.Descrizione.ToLower().Contains(Descrizione.ToLower()));
    ///    }
    ///
    ///    return predicate;
    /// }
    /// </remarks>
    #endregion
	public class $safeitemrootname$ : FilterBase</* PUT HERE THE TYPE OF OBJECT YOU WANT TO FILTER */>, IFilterBase
	{
        public override Expression<Func</* PUT HERE THE TYPE OF OBJECT YOU WANT TO FILTER */, bool>> SetUpFilter()
        {
            var predicate = PredicateBuilder.False</* PUT HERE THE TYPE OF OBJECT YOU WANT TO FILTER */>();

            if (!string.IsNullOrWhiteSpace(SearchPattern))
            {
                predicate = predicate.Or(im => im.Nome != null && im.Nome.ToLower().Contains(SearchPattern));
            }

            return predicate;
        }
	}
}
